package it.polimi.traveldream.beans;

import it.polimi.traveldream.dto.AccomodationDTO;
import it.polimi.traveldream.ejb.ProductManager;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name = "accomodationBean")
@RequestScoped
public class AccomodationBean {

	@EJB
	private ProductManager productManager;

	private AccomodationDTO accomodation;

	public AccomodationBean() {
		this.accomodation = new AccomodationDTO();
	}

	public AccomodationDTO getAccomodation() {
		return this.accomodation;
	}

	public void setAccomodation(AccomodationDTO accomodation) {
		this.accomodation = accomodation;
	}

	public String save() {
		this.productManager.save(this.accomodation);
		return "/employee/products/list?faces-redirect=true";
	}

	public List<AccomodationDTO> getAccomodations() {
		return this.productManager.getAccomodations();
	}

	public List<AccomodationDTO> getFiltered(String city) {
		return this.productManager.getAccomodation(city);
	}

	public String removeAccomodation(AccomodationDTO a) {
		this.productManager.removeAccomodation(a);
		return "?faces-redirect=true";
	}
}
